<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>
        <!--ckeditor核心文件-->
        <script src="/js/ckeditor/ckeditor.js"></script>
        <script>
            $(function () {
                //初始化富文本编辑器
                var ck = CKEDITOR.replace( 'editor');
                $('.inputBtn').click(function () {
                    $('#editForm')[0].reset();//reset不能清空type为hidden的隐藏域,如果type=text,有hidden属性则可以被清空
                    //清除副文本编辑器
                    ck.setData('');
                    $('#coverImg').attr('src','');
                    var json = $(this).data('json');
                    if (json){
                        // console.log(json);
                        $('input[name=id]').val(json.id);
                        $('input[name=grogshopName]').val(json.grogshopName);
                        $('#coverImg').attr('src',json.coverUrl);
                        $('input[name=coverUrl]').val(json.coverUrl);
                        $('input[name=price]').val(json.price);
                        $('input[name=site]').val(json.site);
                        $('input[name=grade]').val(json.grade);
                       /* $('select[name="place.id"]').val(json.placeId);*/
                        $('select[name=state]').val(json.state);


                    }
                    $('#inputModal').modal('show');
                });

                /*$('.submitBtn').click(function () {
                    var content = ck.getData();//获得文本内容
                    console.log(content);
                    $("#editor1").html(content)
                    // $('textarea[name="grogshopComment.content"]').html(content);
                    $('#editForm').ajaxSubmit(function (data) {
                        handleResult(data);
                    })
                });*/

                $(".submitBtn").click(function () {
                    //从ckeditor中获取文章内容
                    var content = ck.getData();
                    console.log(content);
                    //设置form表单中的textarea中(因为文章内容在富文本编辑器中,所以要先取出来,在设置进表单中)
                    $("#editor").html(content)
                    //$("textarea[name='strategyContent.content']").val(content);
                    $("#editForm").ajaxSubmit(function (data) {
                        reload();
                    });

                });
                

            })
        </script>

</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="grogshop"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">酒店管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/grogshop/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword"
                           value="${(qo.keyword)!}" placeholder="请输入标题">
                </div>
                <button id="btn_query" class="btn btn-success">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a role="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加
                </a>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>酒店名称</th>
                    <th>封面</th>
                    <th>价格</th>
                  <#--  <th>入住时间</th>
                    <th>离开时间</th>-->
                    <th>状态</th>
                    <th>所属地区</th>
                    <th>酒店所在地址</th>
                    <th>评分</th>
                </tr>

            <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index+1}</td>
                        <td>${entity.grogshopName}</td>
                        <td><img src="${entity.coverUrl}" width="100px"/></td>
                        <td>${entity.price}</td>
                        <td>${entity.stateString}</td>
                        <td>${entity.region.name}</td>
                        <td>${(entity.site)!}</td>
                        <td>${(entity.grade)!}</td>
                        <td>
                            <a class="btn btn-info btn-xs inputBtn" data-json='${(entity.json)!}' >
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>


<!-- 模态框必须作为body的子标签 -->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/grogshop/saveOrUpdate.do" method="post" id="editForm">
                   <#-- <input type="text" name="id" hidden>-->
                    <input type="hidden" name="id" >
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">酒店名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="grogshopName" >
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">入住价格：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="price" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">酒店所在地址：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="site" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">评分：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="grade" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverImg" width="100%"/>
                            <input type="hidden"  name="coverUrl" >
                            <input type="file" class="form-control" name="file" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属地区：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="region.id" >
                                <#list regions as r>
                                    <option value="${r.id}">${r.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">状态：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="state" >
                                <option value="-1">禁用</option>
                                <option value="0">普通</option>
                                <option value="1">推荐</option>
                                <option value="1">特价</option>
                            </select>
                        </div>
                    </div>

                       <!--文章内容-->
                       <textarea name="grogshopComment.comment" id="editor" rows="10" cols="80">
                    </textarea>
               <#--  <textarea name="grogshopComment.comment" id="editor1" rows="10" cols="80">
                        This is my textarea to be replaced with CKEditor.
                    </textarea>
                    <script>
                        // Replace the <textarea id="editor1"> with a CKEditor
                        // instance, using default configuration.
                        var ck = CKEDITOR.replace('editor1');
                    </script>-->


                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>



</body>
</html>